package com.zzy.furns.web;

import com.zzy.furns.service.AdminService;
import com.zzy.furns.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@SuppressWarnings({"all"})
public class AdminServlet extends BasicServlet {

    private AdminService adminService = new AdminServiceImpl();

    private void adminLogin(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
        String adminname = req.getParameter("adminname");
        String password = req.getParameter("password");

        if (!adminService.queryAdminByAdminnameAndPassword(adminname, password)){
            //账户或密码错误
            req.setAttribute("error","账户或密码错误");
            req.setAttribute("adminname",adminname);
            req.getRequestDispatcher("/views/manage/manage_login.jsp").forward(req,resp);
            return;
        }

        //登陆成功
        //用于权限校验中的放行操作
        req.getSession().setAttribute("loginAdmin",adminname);
        req.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(req,resp);
    }
}
